<?php

namespace App\Models\Recommend;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ApppageRectpl
 * @package App\Models\Recommend
 * @version July 25, 2018, 9:47 am CST
 *
 * @property \App\Models\Recommend\Pagetpl pagetpl
 * @property \App\Models\Recommend\Paneltpl paneltpl
 * @property integer pagetpl_id
 * @property string area
 * @property integer paneltpl_id
 * @property string name
 * @property string title
 * @property string subtitle
 * @property string param
 * @property string description
 */
class ApppageRectpl extends Model
{
    use SoftDeletes;

    public $table = 'apppage_rectpls';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'pagetpl_id',
        'area',
        'paneltpl_id',
        'name',
        'title',
        'subtitle',
        'param',
        'description',
        // 数据类型
        // 'data_type',
        // 数据ID
        // 'data_id',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'pagetpl_id' => 'integer',
        'area' => 'string',
        'paneltpl_id' => 'integer',
        'name'        => 'string',
        'title'       => 'string',
        'subtitle'    => 'string',
        'param'       => 'string',
        'description' => 'string',
        // 数据类型
        // 'data_type'   => 'integer',
        // // 数据ID
        // 'data_id'      =>'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'area' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function pagetpl()
    {
        return $this->hasOne(\App\Models\Application\Pagetpl::class, 'id', 'pagetpl_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function paneltpl()
    {
        return $this->hasOne(\App\Models\Application\Paneltpl::class, 'id', 'paneltpl_id');
    }


 /**
     * 推荐位区位
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     **/
    public function apppageRectplArea()
    {
        return $this->hasMany(\App\Models\Recommend\ApppageRectplArea::class, 'apppage_rectpl_id', 'id');
    }

}
